class Trie {
private:
    vector<Trie*> child;
    bool isEnd;

    Trie* helper(string word){
        Trie* node=this;
        for(int i=0;i<word.length();i++){
            int pos=word[i]-'a';
            if(node->child[pos]==NULL){
                return NULL;
            }
            node=node->child[pos];
        }
        return node;
    }
public:
    Trie():child(26),isEnd(false) {}
    
    void insert(string word) {
        Trie* node=this;
        for(int i=0;i<word.length();i++){
            int pos=word[i]-'a';
            if(node->child[pos]==NULL){
                node->child[pos]=new Trie();
            }
            node=node->child[pos];
        }
        node->isEnd=true;
    }
    
    bool search(string word) {
        Trie* node=helper(word);
        if(node!=NULL&&node->isEnd==true)
            return true;
        else
            return false;
    }
    
    bool startsWith(string prefix) {
        Trie* node=helper(prefix);
        if(node!=NULL)
            return true;
        else
            return false;
    }
};

/**
 * Your Trie object will be instantiated and called as such:
 * Trie* obj = new Trie();
 * obj->insert(word);
 * bool param_2 = obj->search(word);
 * bool param_3 = obj->startsWith(prefix);
 */
